package com.boot.core.result

import java.io.Serializable
import java.util.*

/**
 * 返回结果
 *
 * @author rankai
 * createTime 2017-04-2017/4/20 14:47
 */
class ResultTo : HashMap<String, Any>, Serializable {

    constructor() {
        this[RESULT_CODE] = ResultEnum.SUCCESS.code
        this[RESULT_MESSAGE] = ResultEnum.SUCCESS.message
    }

    constructor(resultEnum: ResultEnum) {
        this[RESULT_CODE] = resultEnum.code
        this[RESULT_MESSAGE] = resultEnum.message
    }

    constructor(resultEnum: ResultEnum, message: String) {
        this[RESULT_CODE] = resultEnum.code
        this[RESULT_MESSAGE] = message
    }

    constructor(code: Int, message: String) {
        this[RESULT_CODE] = code
        this[RESULT_MESSAGE] = message
    }

    fun setData(dataName: String, obj: Any): ResultTo {
        this[dataName] = obj
        return this
    }

    fun setData(map: Map<String, Any>): ResultTo {
        this.putAll(map)
        return this
    }

    companion object {

        private const val serialVersionUID = -6125210369527938613L

        // 返回结果编码
        const val RESULT_CODE = "err_code"
        // 返回结果信息
        private const val RESULT_MESSAGE = "err_message"
    }
}
